<?php

class countryFilter extends sfFilter {

    public function execute($filterChain){
        if ($this->isFirstCall()){
            // Filters don't have direct access to the request and user objects.
            // You will need to use the context object to get them
            $context = $this->getContext();
            $request = $this->getContext()->getRequest();
            $response = $this->getContext()->getResponse();
            $user    = $this->getContext()->getUser();

            //if(!$request->getCookie($this->getParameter('cookie_name'))){
            if(!$user->hasAttribute('scountry')){
                $country_id = 169;
                /* cookie expira en 15 dias */
                /* 169: ID Perú en BD */
                //$response->setCookie($this->getParameter('cookie_name'),$country_id, time()+60*60*24*15, '/');

                $country = CountryPeer::retrieveByPK($country_id);
                $user->setAttribute('scountry',$country);
            }

            $filterChain->execute();
        }
    }

}
?>